/**
 * PageMarket
 * AboutActivity.java
 * com.android.pagemarket.ui.activity.setting
 * 
 */
package com.android.pagemarket.ui.activity.setting;

import android.os.Bundle;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.pagemarket.MyApplication;
import com.android.pagemarket.R;
import com.android.pagemarket.ui.activity.base.TemplateActivity;
import com.android.pagemarket.ui.activity.main.MainIndexActivity;
import com.android.pagemarket.ui.adapter.AdvListAdapter;
import com.android.pagemarket.ui.widget.FlowView;
import com.android.pagemarket.ui.widget.MorePopWindow;
import com.android.pagemarket.ui.widget.TitleBar;
import com.android.pagemarket.ui.widget.TitleBar.OnTitleClickListener;
import com.android.pagemarket.util.NotifyListener;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-10-29
 * @see : 关于同舟视图
 * @Copyright : copyrights reserved by personal 2007-2012
 **********************************************************/
public class AboutActivity extends TemplateActivity implements OnClickListener
{
    private FlowView adv_lay;
    private AdvListAdapter listAdapter;
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);       
        setContentView(R.layout.activity_about);
        initViews();        
        listAdapter.loadMainAdvs();
    }
    
    @Override
    protected void onResume()
    {
        super.onResume();       
    }
    
    @Override
    public void onBackPressed()
    {
        if( getParent() instanceof MainIndexActivity)
        {
            ((MainIndexActivity)getParent()).onBackPressed();
        }
    }
    
    @Override
    protected void onPause()
    {     
        super.onPause();
    }
    
    @Override
    protected void setupTitleBar(TitleBar titleBar)
    {
        titleBar.setTitle(R.string.title_start);
        titleBar.setLeftVisible(false);
        titleBar.setRigthText(R.string.tx_more);
        titleBar.setOnTitleClickListener(new OnTitleClickListener()
        {
            @Override
            public void onRightClick()
            {
                // 弹出更多弹出框
                showMorePopWin();
            }
        }, false, true);
    }
    
    private void initViews()
    {
        adv_lay = getViewById(R.id.adv_lay);
        adv_lay.setAutoSlide(true);
        listAdapter = new AdvListAdapter(this);
        adv_lay.setAdpter(listAdapter);
        
        TextView tx_cz = getViewById(R.id.tx_cz);
        tx_cz.setText(Html.fromHtml("0769-82218777<br>0769-82218111"));
    }
    
    private void showMorePopWin()
    {
        if(getPopupWin() == null)
        {
            setPopWin(new MorePopWindow(this,this));
        }
        getPopupWin().showAtLocation(getParent().getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
    }

    @Override
    public void onClick(View v)
    {
        switch(v.getId())
        {
            case R.id.btn_checkversion:
            {
                if(!MyApplication.getContext().isNetWorkAvailable())
                {
                    showNoNetworkDialog();
                    return;
                }
                showLoding(null, "版本检测...");
                if( getParent() instanceof MainIndexActivity)
                {
                    ((MainIndexActivity)getParent()).checkUpdate(new NotifyListener<Boolean>()
                    {
                        @Override
                        public void onSucceed(Boolean result)
                        {
                            hideLoding();
                            if(result)
                            {
                                showToast("您的版本已经是最新版本");
                            }
                        }
                        @Override
                        public void onError(int resultCode)
                        {
                            hideLoding();
                            showToast("检测失败！");
                        }
                    });
                }
                break;
            }
            case R.id.btn_report:
            {
                ReportActivity.startActivity(this);
                break;
            }
            case R.id.btn_about:
            {
                AboutDetailActivity.startActivity(this);
                break;
            }
        }
    }
}